package com.wn.web;

import com.wn.auth.JWTUtil;
import com.wn.common.Const;
import com.wn.common.PageParam;
import com.wn.ov.DepartmentUserOv;
import com.wn.ov.UserOv;
import com.wn.pojo.Drug;
import com.wn.pojo.Scheduling;
import com.wn.pojo.User;
import com.wn.resopnse.ServerResponse;
import com.wn.service.HumenService;
import com.wn.service.NurseService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("humen")
public class HumenController {
    @Autowired
    private HumenService humenService;
    @Autowired
    private NurseService nurseService;

    /**
     * 人员信息录入
     * @param user
     * @return
     */
    @PostMapping("add-person")
    @ApiOperation("人员信息录入")
    public ServerResponse addHumen(@RequestHeader("token")String token,@RequestBody @Validated User user){
        UserOv userOv = JWTUtil.parserToken(token, Const.PUBLIC_KEY);
        user.setCreateUserId(userOv.getId());
        user.setUpdateUserId(userOv.getId());

        return humenService.addHumen(user);
    }

    /**
     * 修改人员信息
     * @param
     * @return
     */
    @PostMapping("update-person")
    @ApiOperation("修改人员信息")
    public ServerResponse updateHumen(@RequestBody @Validated DepartmentUserOv departmentUserOv){
        int roleId=departmentUserOv.getRoleId();
        int postId=departmentUserOv.getPostId();
        int id=departmentUserOv.getId();

        User user=new User();
        user.setId(id);
        user.setPostId(postId);
        user.setRoleId(roleId);

        return humenService.updateHumen(user);
    }

    /**
     * 物理删除
     * @param
     * @return
     */
    @PostMapping("delete-person")
    @ApiOperation("物理删除")
    public ServerResponse deleteOneTrue( @RequestBody DepartmentUserOv departmentUserOv){
        int id=departmentUserOv.getId();

        return humenService.deleteOneTrue(id);

    }

    /**
     * 逻辑删除
     * @param user
     * @return
     */
    @PostMapping("deleteLogical")
    @ApiOperation("逻辑删除")
    public ServerResponse deleteLogical(User user){
        return humenService.deleteLogical(user);
    }

    /**
     * 批量物理删除
     * @param Ids
     * @return
     */
    @PostMapping("deleteBatchTrue")
    @ApiOperation("批量物理删除")
    public ServerResponse deleteBatchTrue(List<Integer> Ids){
        return humenService.deleteBatchTrue(Ids);
    }

    /**
     * 批量逻辑删除
     * @param Ids
     * @return
     */
    @PostMapping("deleteBatchLogical")
    @ApiOperation("批量逻辑删除")
    public ServerResponse deleteBatchLogical(List<Integer> Ids){
        return humenService.deleteBatchLogical(Ids);
    }

    /**
     * 逻辑恢复
     * @param user
     * @return
     */
    @PostMapping("recoverLogical")
    @ApiOperation("逻辑恢复")
    public ServerResponse recoverLogical(User user){
        return humenService.recoverLogical(user);
    }

    //获得非病人列表
    @PostMapping("getPersonList")
    public ServerResponse getPersonList(@RequestHeader("token")String token,
                                        @RequestBody PageParam<User> pageParam){
        return humenService.getPersonList(pageParam);
    }
    //权限列表
    @PostMapping("roleMsg")
    public ServerResponse getRoleList(){
        return humenService.getRoleList();
    }
    //排班列表
    @PostMapping("schedulingList")
    public ServerResponse getSchedulingList(@RequestHeader("token")String token,@RequestBody PageParam<Scheduling> pageParam){
        return humenService.getSchedulingList(pageParam);
    }
    //添加排班表
    @PostMapping("add-scheduling")
    public ServerResponse addScheduling(@RequestBody Scheduling scheduling){
        return humenService.addScheduling(scheduling);
    }
    //修改排班
    @PostMapping("update-scheduling")
    public ServerResponse updateScheduling(@RequestBody Scheduling scheduling){
        return humenService.updateScheduling(scheduling);
    }
    //删除排班
    @PostMapping("delete-scheduling")
    public ServerResponse deleteScheduling(@RequestBody Scheduling scheduling){
        int id=scheduling.getId();
        return humenService.deleteScheduling(id);
    }

    //护士列表
    @PostMapping("nurseMsg")
    public ServerResponse getNurseList(){
        return  nurseService.getNurseList();
    }
}
